/**
 * @param {string} s
 * @return {number}
 */
// hash表 双指针
var lengthOfLongestSubstring = function(s) {
    if (s.length < 2) return s.length
    let hash = {}, ans = 0
    for (let l = 0, r = 0; r < s.length; r++) {
        let c = s[r]
        if (!(c in hash)) hash[c] = r
        else {
            if (l <= hash[c])
                l = hash[c] + 1
            hash[c] = r
        }
        ans = Math.max(ans, r - l + 1)
    }
    return ans
};

lengthOfLongestSubstring("abcabcbb")